{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "1b81d881",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import cv2 as cv\n",
    "from matplotlib import pyplot as plt\n",
    "\n",
    "img = cv.imread('../data/sudoku.png',0)\n",
    "# img = cv.medianBlur(img,9)\n",
    "\n",
    "laplacian = cv.Laplacian(img,cv.CV_64F, ksize=1)\n",
    "# lap = cv.convertScaleAbs(laplacian)\n",
    "sobelx = cv.Sobel(img,cv.CV_64F,1,0,ksize=5)\n",
    "sobely = cv.Sobel(img,cv.CV_64F,0,1,ksize=5)\n",
    "sobelxy = cv.Sobel(img,cv.CV_64F,1,1,ksize=5)\n",
    "\n",
    "res = np.hstack((img, img))\n",
    "\n",
    "cv.imshow(\"img\", img)\n",
    "cv.imshow(\"laplacian\", laplacian)\n",
    "cv.waitKey(0)\n",
    "cv.imshow(\"laplacian\", sobelx)\n",
    "cv.waitKey(0)\n",
    "cv.imshow(\"laplacian\", sobely)\n",
    "cv.waitKey(0)\n",
    "cv.imshow(\"laplacian\", sobelxy)\n",
    "cv.waitKey(0)\n",
    "cv.destroyAllWindows()\n",
    "\n",
    "# plt.subplot(2,2,1),plt.imshow(img,cmap = 'gray')\n",
    "# plt.title('Original'), plt.xticks([]), plt.yticks([])\n",
    "# plt.subplot(2,2,2),plt.imshow(laplacian,cmap = 'gray')\n",
    "# plt.title('Laplacian'), plt.xticks([]), plt.yticks([])\n",
    "# plt.subplot(2,2,3),plt.imshow(sobelx,cmap = 'gray')\n",
    "# plt.title('Sobel X'), plt.xticks([]), plt.yticks([])\n",
    "# plt.subplot(2,2,4),plt.imshow(sobely,cmap = 'gray')\n",
    "# plt.title('Sobel Y'), plt.xticks([]), plt.yticks([])\n",
    "\n",
    "# plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "6193cf42",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAWcAA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q2jVVK7N2dYa168w16badVDgbY4ypDRtzNsYYB1k4G2OMgyycjTHGQRbOxhjjIAtnY4xxkIWzMcY4yMLZGGMcZOFsjDEOsnA2xhgH/T/ugHXauCC3DgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 3 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import cv2 as cv\n",
    "from matplotlib import pyplot as plt\n",
    "img = cv.imread('../data/whiteRect.png',0)\n",
    "# Output dtype = cv.CV_8U\n",
    "sobelx8u = cv.Sobel(img,cv.CV_8U,1,0,ksize=5)\n",
    "# Output dtype = cv.CV_64F. Then take its absolute and convert to cv.CV_8U\n",
    "sobelx64f = cv.Sobel(img,cv.CV_64F,1,0,ksize=5)\n",
    "abs_sobel64f = np.absolute(sobelx64f)\n",
    "sobel_8u = np.uint8(abs_sobel64f)\n",
    "plt.subplot(1,3,1),plt.imshow(img,cmap = 'gray')\n",
    "plt.title('Original'), plt.xticks([]), plt.yticks([])\n",
    "plt.subplot(1,3,2),plt.imshow(sobelx8u,cmap = 'gray')\n",
    "plt.title('Sobel CV_8U'), plt.xticks([]), plt.yticks([])\n",
    "plt.subplot(1,3,3),plt.imshow(sobel_8u,cmap = 'gray')\n",
    "plt.title('Sobel abs(CV_64F)'), plt.xticks([]), plt.yticks([])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "01c9b63f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
